package models;
 
import java.util.*;
import javax.persistence.*;
 
import play.db.jpa.*;
 
@Entity
public class Message extends Model {
 
	public int id_topic;
	public String titre;
    public Date date;
    
    @Lob
    public String message;
    
    @ManyToOne
    public User user;
	
	@OneToMany(mappedBy="topic", cascade=CascadeType.ALL)
	public List<Reponse> reponses;
    
    public Message(User author, String title, String content) 
	{
		//this.reponses = new ArrayList<Reponse>();
        this.user = author;
        this.titre = title;
        //this.message = content;
        this.date = new Date();
    }
	
	public Message addReponse(Message topic, User user, String content) 
	{
		Reponse newReponse = new Reponse(topic, user, content).save();
		this.reponses.add(newReponse);
		return this;
	}
 
}